package com.mine.frame.mylandemo.ui.study

import android.os.Bundle
import android.view.MotionEvent
import com.mine.frame.common.base.BaseActivity
import com.mine.frame.common.empty.EmptyPresenter
import com.mine.frame.common.empty.IEmpty
import com.mine.frame.mylandemo.R
import kotlinx.android.synthetic.main.atv_move_view.*

/**
 * @Date 2022/4/27
 * Description:
 */
class MoveViewAtv : BaseActivity<IEmpty, EmptyPresenter>(), IEmpty {

    private var moveVW = 0
    private var moveVH = 0
    override fun initLayoutId(): Int = R.layout.atv_move_view

    override fun initPresenter(): EmptyPresenter = EmptyPresenter(this)

    override fun initLayoutAfter(savedInstanceState: Bundle?) {
        ivMove.animate().alpha(0f).setDuration(300).start()


    }

    override fun onTouchEvent(event: MotionEvent?): Boolean {
        event?.let {
            when (it.action) {
                MotionEvent.ACTION_DOWN -> {
                    ivMove.animate().alpha(1f).setDuration(100).start()
                    moveVH = ivMove.bottom
                    moveVW = ivMove.right + ivMove.width / 2
                }
                MotionEvent.ACTION_MOVE -> {
                    ivMove.translationY = it.rawY - moveVH
                    //ivMove.translationX = it.rawX - moveVW
                }
                MotionEvent.ACTION_UP -> {
                    ivMove.animate().alpha(0f).setDuration(200).start()
                }
            }
        }
        return super.onTouchEvent(event)
    }
}